package com.victualler.core.config.menu.controller.impl;

import com.victualler.core.base.controller.impl.BaseRestControllerImpl;
import com.victualler.core.common.dto.PageDto;
import com.victualler.core.config.menu.controller.MenuController;
import com.victualler.core.config.menu.dto.MenuDto;
import com.victualler.core.config.menu.dto.request.MenuRequestDto;
import com.victualler.core.config.menu.dto.response.MenuResponseDto;
import com.victualler.core.config.menu.entity.MenuDao;
import com.victualler.core.config.menu.repository.MenuQueryRepository;
import com.victualler.core.config.menu.repository.MenuRepository;
import com.victualler.core.config.menu.service.MenuService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: Guoshichang
 * @discription:    
 */
@RestController
@RequestMapping("/core/config/menu")
public class MenuControllerImpl extends BaseRestControllerImpl<MenuDao,MenuRepository,MenuQueryRepository,MenuService> implements MenuController {
    /**
     * @author Guoshichang
     * @since 13:39 on 2018/7/7.
     * @param menuRequestDto
     * @Function  根据条件入参PermissionRequestDto动态分页查询权限
     */
    @RequestMapping("/getByRequestDto")
    @Override
    public PageDto<MenuResponseDto> getByRequestDto(@RequestBody MenuRequestDto menuRequestDto, @RequestParam("pageNo") int from , @RequestParam("limit") int limit){
        return this.baseService.getByRequestDto(menuRequestDto,from,limit);
    }


    /**
     * @author Guoshichang
     * @since 0:45 on 2018/9/15.
     * @return  MenuDto
     * @Function
     */
    @RequestMapping("/getAllMenuTree")
    @Override
    public MenuDto getAllMenuTree() {
        List<MenuDto> allList = this.baseService.getAllMenu();
        //做权限
        return this.baseService.chengeToMenuDto(allList);
    }

    /**
     * @author Guoshichang
     * @since 19:52 on 2018/8/28.
     * @param name 菜单名称
     * @return List
     * @Function  根据菜单名称模糊查询菜单
     */
    @RequestMapping("/getByName")
    @Override
    public List<MenuDao> getByName( @RequestParam("name") String name) {
        return this.baseService.getByName(name);
    }
}
